import { Controller, Get, Post, Body, Req, Param } from '@nestjs/common';
import { UserService } from './user.service';
import { UserEntity } from './entities/user.entity';
import { Request } from 'express';
import { Public } from 'src/common/decorators/public.decorator';
@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('list/:page/:limit')
  findAll(@Param('page') page, @Param('limit') limit): Promise<any> {
    return this.userService.findAll(page, limit);
  }

  @Get('info')
  getInfo(@Req() req: Request) {
    const authorization = req.headers.authorization;
    return this.userService.getInfo(authorization);
  }

  @Post('logout')
  @Public()
  logout() {
    return '退出成功';
  }

  @Post('save')
  create(@Body() user: UserEntity) {
    return this.userService.create(user);
  }

  @Post('login')
  login(@Body() user: UserEntity) {
    return this.userService.login(user);
  }
}
